
const app = getApp();

Page({
  data: {
    listData: {
      onItemTap: 'handleListItemTap',
      data: [],
      longTap :'handleListLongTap',
    },
  },
  handleListItemTap(e) {
    var url = app.globalData.url;
    var index = e.currentTarget.dataset.index;
    var rid = this.data.listData.data[index].id;
    var followMan = '';
    var currentData='';
    var createMan = '';
    var createUid = '';
    var createDid = '';
    dd.httpRequest({ 
        url:url+'/api/BusinessReport/selBusinessReportByRid',
        method:'post',
        datatype:'json',
        data:{
          rId:rid,
        },
        success:function(res){
            followMan = res.data.data.followMan;
            createMan = res.data.data.rFzr;
            createUid = res.data.data.cUid;
            createDid = res.data.data.departmentId;
            dd.httpRequest({
                url: url+'/api/hr/weekly/yearMonth',
                method: 'POST',
                data: {
                },
                dataType: 'json',
                success: function(res) {
                    currentData  =res.data;
                    dd.navigateTo({
                      url: '../../index/business/weekly/weekly?rid='+rid+'&currentData='+currentData+'&followMan='+followMan+'&createMan='+createMan+'&createUid='+createUid+'&createDid='+createDid+'&db=db'
                    })
                },
                fail: function(res) {
                  dd.alert({content: 'fail'});
                },
                complete: function(res) {
                  // dd.alert({content: 'complete'});
                }
            });
        } 
      });
      
    
  },
  selName(e){
    var that =this;
    var name =e.detail.value;
    var isAdmin=app.globalData.userinfo.isAdmin;  //管理员默认全部可查
    var isBoss= app.globalData.userinfo.isBoss;  //老板全部可查
    var isLeaderInDepts=app.globalData.userinfo.isLeaderInDepts; //是否为部门主管   String类型！
    var isDept =isLeaderInDepts.split(":") //分割字符后 前后有{}
    if(isBoss||isAdmin){
      that.selWeekDaiban(1,name);
    }else if(isDept[1]=='true}'){
      that.selWeekDaiban(2,name);
    }else{
      that.selWeekDaiban(3,name);
    }

  },
  selWeekDaiban(type,name){
    var that =this;
    var Uid = app.globalData.userinfo.userid;
    var url = app.globalData.url;
    var department=app.globalData.userinfo.department;    //部门id

    var summList =[];
      dd.httpRequest({ 
            url:url+'/api/hr/weekly/getweekDaiban',
            method:'post',
            datatype:'json',
            data:{
                departmentId:department,
                Uid:Uid,
                type:type,
                name:name,
            },
            success:function(res){
              if(res.data.data==undefined){
                that.setData({
                    'listData.data':[],
                })
              }else{
                res.data.data.forEach(function (item,index){
                  summList.push({
                      'title': res.data.data[index].rName,
                      'arrow': 'horizontal',
                      'extra': res.data.data[index].followMan,
                      'id': res.data.data[index].rId,
                  })
                  that.setData({
                    'listData.data':summList,
                  })
               });
              }
            } 
     });
  },

 onShow(options) {
    var that =this;
    var isAdmin=app.globalData.userinfo.isAdmin;  //管理员默认全部可查
    var isBoss= app.globalData.userinfo.isBoss;  //老板全部可查
    var isLeaderInDepts=app.globalData.userinfo.isLeaderInDepts; //是否为部门主管   String类型！
    var isDept =isLeaderInDepts.split(":") //分割字符后 前后有{}
    var name='';
    if(isBoss||isAdmin){
      that.selWeekDaiban(1,name);
    }else if(isDept[1]=='true}'){
      that.selWeekDaiban(2,name);
    }else{
      that.selWeekDaiban(3,name);
    }
  },
  
});
